package com.demo.core.dao.impl;

import java.util.HashMap;
import java.util.Map;

import com.demo.core.dao.UserDao;
import com.demo.core.dao.impl.base.PageCoreDaoSupport;
import com.demo.core.model.User;
import com.demo.core.model.support.GeneralExecuteModel;

/**
 * 用户表数据访问层
 * 
 * @author ryuu.kk
 *
 */
public class UserDaoImpl extends PageCoreDaoSupport<User, Long> implements UserDao{
	/**
	 * 用户空间 
	 */
	protected final static String USER_SPACE = "userSpace.";
	/**
	 * 数据库的表名
	 */
	protected final static String TABLE_NAME = "T_CORE_USER";
	/**
	 * 数据库表的主键名称
	 */
	protected final static String TABLE_PK_NAME = "ID";
	@Override
	public int updateStatus(User user, Map<String, Object> userStatus) {
		cacheClear();
		userStatus.put("user", user);
		return getSqlMapClientTemplate().update(USER_SPACE + "changeUserStatus", userStatus);
	}
	@Override
	public int updateOrg(User user, Map<String, Object> userInfo) {
		cacheClear();
		userInfo.put("user", user);
		return getSqlMapClientTemplate().update(USER_SPACE + "changeUserOrg", userInfo);
	}
	@Override
	public int resetPassword(String newPassword, Map<String, Object> params) {
		cacheClear();
		if (params == null) {
			params = new HashMap<String, Object>();
		}
		params.put("password", newPassword);
		return getSqlMapClientTemplate().update(USER_SPACE + "resetPassword", params);
	}
	@Override
	protected String nameSpace() {
		return USER_SPACE;
	}
	@Override
	protected void doInit(GeneralExecuteModel<Long> model) {
		model.setPk(TABLE_PK_NAME);
		model.setTable(TABLE_NAME);
	}
}
